﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Serialization;
using EC_Agent.HotelClass;
using EC_Agent.Models;


namespace EC_Agent
{
    public partial class Hotel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Search_Click(object sender, EventArgs e)
        {
            HotelWS hl = null; 
            DataSet dataset = new NhaCungCapModels().ListUrlNhaCungCap("Hotel");
            DataSet dsALL = new DataSet();
            foreach (DataRow Row in dataset.Tables[0].Rows)
            {
                hl = new HotelWS(Row["WS"].ToString());
                //hl.CookieContainer = new System.Net.CookieContainer();
                //hl.DangNhap(Row["UsernameA"].ToString(), Row["PasswordA"].ToString());
                DateTime dates = Convert.ToDateTime(StartDate.Text);
                DateTime datee = Convert.ToDateTime(EndDate.Text);                
                
                ArrayToDataTable exec = new ArrayToDataTable();
                DataTable rTable = null;
                
                DataSet dslhp = new DataSet();
                rTable = exec.ConvertArrayToDataTable(hl.LayDSLoaiHangPhongHoTro(dates, datee));
                dslhp.Tables.Add(rTable);
                DataTable LoaiHangPhong = dslhp.Tables[0];

                rTable = exec.ConvertArrayToDataTable(hl.LayDSLoaiPhong());
                dslhp.Tables.Add(rTable);
                DataTable LoaiPhong = dslhp.Tables[1];

                rTable = exec.ConvertArrayToDataTable(hl.LayDSHangPhong());
                dslhp.Tables.Add(rTable);
                DataTable HangPhong = dslhp.Tables[2];

                DataRelation relation = null;
                relation = new DataRelation("LoaiHangPhong_LoaiPhong", LoaiPhong.Columns["MaLoaiPhong"], LoaiHangPhong.Columns["MaLoaiPhong"]);
                dslhp.Relations.Add(relation);
                relation = new DataRelation("LoaiHangPhong_HangPhong", HangPhong.Columns["MaHangPhong"], LoaiHangPhong.Columns["MaHangPhong"]);
                dslhp.Relations.Add(relation);

                DataTable dtloaihangphong = new DataTable("LHangPhong");
                dtloaihangphong.Columns.Add("LoaiPhong", System.Type.GetType("System.String"));
                dtloaihangphong.Columns.Add("HangPhong", System.Type.GetType("System.String"));
                dtloaihangphong.Columns.Add("SoLuong", System.Type.GetType("System.Int32"));
                dtloaihangphong.Columns.Add("GiaPhong", System.Type.GetType("System.Int32"));
                dtloaihangphong.Columns.Add("Company", System.Type.GetType("System.String"));
         
                foreach (DataRow LHPRow in LoaiHangPhong.Rows)
                {
                    DataRow parentRow = null;
                    parentRow = LHPRow.GetParentRow("LoaiHangPhong_LoaiPhong");
                    DataRow newRow = dtloaihangphong.NewRow();
                    newRow["LoaiPhong"] = parentRow["TenLoaiPhong"].ToString();
                    parentRow = LHPRow.GetParentRow("LoaiHangPhong_HangPhong");
                    newRow["HangPhong"] = parentRow["TenHangPhong"].ToString();
                    newRow["SoLuong"] = LHPRow["SoLuong"].ToString();
                    newRow["GiaPhong"] = LHPRow["GiaPhong"].ToString();
                    newRow["Company"] = Row["TenNCC"].ToString();
                    dtloaihangphong.Rows.Add(newRow);
                }
                dsALL.Merge(dtloaihangphong); 
              
            }
            DSPhongDat.DataSource = dsALL;
            DSPhongDat.DataBind();

        }
    }
}